﻿using System;
using System.IO;
using Jayden.Dll.Core;
using Jayden.Dll.Core.Persistence;
using Jayden.Dll.Series;
using Jayden.Dll.Series.Providers;

namespace SeriesImport
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("Deleting previous database ...");
			File.Delete("database.db");
			Configuration configuration = new Configuration("Configuration.xml");
			using (UnitOfWork uow = new UnitOfWork(configuration.GetConfiguration("UnitOfWork")))
			{

				Console.WriteLine("Retrieving data from provider epguide.com ...");
				EpguidesDotCom provider = new EpguidesDotCom(uow);
				foreach (ShowInfo show in provider.Shows())
				{
					Console.WriteLine("\t" + show.Title);
					uow.MarkNew(show);
					if (show.Episodes != null)
					{
						show.EpisodesCount = show.Episodes.Count;
						foreach (EpisodeInfo episode in show.Episodes)
							uow.MarkNew(episode);
					}
				}

				Console.WriteLine("Writing database ...");
				uow.Commit();
			}
		}
	}
}
